//前提
var mongoose=require("mongoose")

//引用插件
var mongoosePaginate = require('mongoose-paginate');

//约束
var schema = new mongoose.Schema({
   username:{
       type:String,
       required:[true,"用户名不能为空"]
   },
   password:{
       type:String,
       required:[true,"密码不能为空"],
       validate:{
        validator: function(data) {
          return /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,64}$/.test(data);
        },
        message: '密码只能为6~64位的字母混合数字' //VALUE代表phone存放的值
      },
   },
   email:{
       type:String,
       required:[true,"邮箱不能为空"],
       validate:{
        validator: function(data) {
          return /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(data);
          },
        message: '邮箱格式不正确' //VALUE代表phone存放的值
        },
      },
    age:{
        type:Number,
        required:[true,"年龄不能为空"],
        min: [18, '您的年龄未满18周岁'],
    },
    sex:Boolean,
    reg_data:{
        type:Date,
        default:Date.now
    },
    address:{
        type: String,
        maxlength:30,
        minlength:[8, '地址所在地必须超过8个字']
    },
    problem:{
        type:Object
    },
    hobbies:{
        type:Array
    },
    drink: {
        type: String,
        enum: ['Coffee', 'Tea'],
      }
});



//引入插件
schema.plugin(mongoosePaginate);

//实例化
module.exports=mongoose.model('Users',  schema, 'user'); // Model.paginate()